package com.zdkj.subway.check.util;

import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ExcelCellUtil {

    //获取cell的数据
    public static String getCellContent(Cell cell){
        String cellValue="";
        if(cell == null) {
            return "";
        }else if(cell.getCellTypeEnum().ordinal() == org.apache.poi.ss.usermodel.CellType.NUMERIC.ordinal()) {
            if(HSSFDateUtil.isCellDateFormatted(cell)) {
                SimpleDateFormat sm=new SimpleDateFormat("yyyy-MM-dd");
                Date javaDate = HSSFDateUtil.getJavaDate(Double.valueOf(cell.getNumericCellValue()));
                cellValue = sm.format(javaDate);
            }else{
                double value = cell.getNumericCellValue();
                DecimalFormat decimalFormat = new DecimalFormat("0");
                cellValue = decimalFormat.format(value);
            }
        }else if (cell.getCellTypeEnum().ordinal() == org.apache.poi.ss.usermodel.CellType.STRING.ordinal()){
            cellValue = cell.getStringCellValue();
        }else if (cell.getCellTypeEnum().ordinal() == org.apache.poi.ss.usermodel.CellType.BLANK.ordinal()){
            cellValue = "";
        }else {

            return "";
        }
        return cellValue;
    }
}
